package com.sd.service.impl;

import com.sd.dao.StudentHospitalDao;
import com.sd.entity.StudentHospital;
import com.sd.entity.StudentHospitalVo;
import com.sd.service.StudentHospitalService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 学生报名(StudentHospital)表服务实现类
 *
 * @author makejava
 * @since 2021-05-17 16:42:05
 */
@Service("studentHospitalService")
public class StudentHospitalServiceImpl implements StudentHospitalService {
    @Resource
    private StudentHospitalDao studentHospitalDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public StudentHospital queryById(Integer id) {
        return this.studentHospitalDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<StudentHospitalVo> queryAllByLimit(int offset, int limit,StudentHospital studentHospital) {
        return this.studentHospitalDao.queryAllByLimit(offset, limit,studentHospital);
    }

    /**
     * 新增数据
     *
     * @param studentHospital 实例对象
     * @return 实例对象
     */
    @Override
    public StudentHospital insert(StudentHospital studentHospital) {
        studentHospital.setCreateTime(new Date());
        this.studentHospitalDao.insert(studentHospital);
        return studentHospital;
    }

    /**
     * 修改数据
     *
     * @param studentHospital 实例对象
     * @return 实例对象
     */
    @Override
    public StudentHospital update(StudentHospital studentHospital) {
        this.studentHospitalDao.update(studentHospital);
        return this.queryById(studentHospital.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.studentHospitalDao.deleteById(id) > 0;
    }

    @Override
    public Map<String, Long> getCount(StudentHospital studentHospital) {
        return studentHospitalDao.getCount( studentHospital);
    }

    /**
     * @create by: Teacher陈（86521760@qq.com）
     * @description: 批量删除
     * @create time: 2021/4/30 10:02
     * @param studentList
     * @return
     */
    @Override
    public boolean deleteStudentByIds(List<StudentHospital> studentList) {
        int i = studentHospitalDao.deleteStudentByIds(studentList);
        if(i>0){
            return true;
        }
        return false;
    }

    /**
     * @create by: Teacher陈（86521760@qq.com）
     * @description: 统计图业务方法
     * @create time: 2021/6/23 17:14
     * @return
     */
    @Override
    public List<Map<String, Object>> getMyCount() {
        return studentHospitalDao.getMyCount();
    }

    @Override
    public Map<String, Long> getCountAlready(Integer businessId) {
        return studentHospitalDao.getCountAlready(businessId);
    }
}